<?php
namespace app\admin\model;

use think\Model;
class User extends Model
{
	
    public function check($username, $passwd)
    {
        $this->create();
        $where = [
            'username' => $username,
            'passwd' => md5($passwd),
        ];
        $result = $this->where($where)->find();
        return $result;
    }
	
	public function manageInfo()
	{
		$manage_info = $this->select();
		return $manage_info;
	}
	
	public function addUser()
	{
		$data['username'] = I('post.username');
		$data['group_id']=I('post.group_id');
		$data['passwd'] = md5(I('post.passwd'));
		$data['lasttime'] = time();
		$add_user = $this->add($data);
		return $add_user;
		
	}
	
	
	public function editInfo($id)
	{
		$where['id']=$id;
		$edit_info = $this->where($where)->find();
		return $edit_info;
	}
	
	public function postEdit()
	{
		
		$where['id'] = $_POST['id'];
		$data['group_id'] = $_POST['group_id'];
		$data['username'] = $_POST['username'];
		$data['passwd'] = md5($_POST['passwd']);
		$data['lasttime'] = time();
		$post_edit = $this->where($where)->save($data);
		return $post_edit;
		
		
	}
	
	public function delUser()
	{
		$where['id']=I('get.id');
		$there['uid']=I('get.id');
		$del_user = $this->where($where)->delete();
		M('authGroupAccess')->where($there)->delete();
		return $del_user;
	}

	public function mLog()
	{
		$manage_log =M('log')->order('id desc')->select();
	    return $manage_log;
	}
	
	public function delManageLog($time)
	{
		$where['time'] = array('lt',$time);
		$del = M('log')->where($where)->delete();
		return $del;
	}

	/**
	 *  用户组管理
	 */

	public function group_info()
	{
	 $info = M('authGroup')->select();
	 return $info;
	}
	public function group_add()
	{
		$data['title'] = I('post.title');
		$data['description'] = I('post.description');
		$roles_add = M('authGroup')->add($data);
		return $roles_add;
	}
	
	public function group_edit($id)
	{
		$where['id']=$id;
		$info = M('authGroup')->where($where)->find();
		return $info;
	}
	
	public function postdata()
	{
		$where['id']=I('post.id');
		$data['title'] = I('post.title');
		$data['description'] = I('post.description');
		$add = M('authGroup')->where($where)->save($data);
		return $add;
	}
	
	public function group_del($id)
	{
		$where['id']=$id;
		$del = M('authGroup')->where($where)->delete();
		return $del;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
